package com.cskaoyan.com.generic.generic5;

public class Demo3 {
    public static void main(String[] args) {

        // Comparable接口定义了一个compareTo方法
        // 用来作为大小比较的方法
        // "自然顺序":
        //  专门指代 通过Comparable接口compareTo方法所比较大小结果


        // 泛型通配有什么用. 举个例子

//        String str1 = "zs";
//        String str2 = "ls";
//        int i = str1.compareTo(str2);
//        System.out.println(i);


//        Student zs = new Student("zs", 18);
//        Student ls = new Student("ls", 18);
//        int i = zs.compareTo(ls);
//        System.out.println(i);

        ComUtils<String> comUtils = new ComUtils<String>();
        int com = comUtils.com("zs", "ls");


        ComUtils<Student> comUtils2 = new ComUtils<Student>();
        int com1 = comUtils2.com(new Student("zs", 18),
                new Student("ls", 20));

    }
}


// 专门定义一个用来比较的工具类
class ComUtils <T extends Comparable> {

    public int com(T t1, T t2){

        int com = t1.compareTo(t2);

        return com;
    }
}








class Student implements Comparable<Student> {
    String name;
    int age;
    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }
    @Override
    public int compareTo(Student o) {
        int com = name.compareTo(o.name);
        com = com == 0 ? age - o.age : com;

        return com;
    }
}